package pl.register.android.lesson;

import pl.register.android.chapter.ChapterTitle;
import pl.register.android.homework.HomeworkTopic;
import pl.register.android.classes.ClassesTopic;
import pl.register.android.util.time.DateUtil;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-12
 */
public class LessonProgram implements Serializable, Comparable<LessonProgram>{

    private Long id;

    private List<ClassesTopic> classesTopics;

    private HomeworkTopic homeworkTopic;

    private ChapterTitle chapterTitle;

    private Date classesDate;

    private Date homeworkDate;

    private TagLesson tagLesson;

    private int order;

    public LessonProgram(Long id, int order) {
        this.id = id;
        this.order = order;
    }

    public LessonProgram(Long id, int order, List<ClassesTopic> classesTopics, HomeworkTopic homeworkTopic, ChapterTitle chapterTitle) {
        this.id = id;
        this.order = order;
        this.classesTopics = classesTopics;
        this.homeworkTopic = homeworkTopic;
        this.chapterTitle = chapterTitle;
    }

    public LessonProgram newReferences() {
        return new LessonProgram(id, order, classesTopics, homeworkTopic, chapterTitle);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<ClassesTopic> getClassesTopics() {
        return classesTopics;
    }

    public void setClassesTopics(List<ClassesTopic> classesTopics) {
        this.classesTopics = classesTopics;
    }

    public HomeworkTopic getHomeworkTopic() {
        return homeworkTopic;
    }

    public void setHomeworkTopic(HomeworkTopic homeworkTopic) {
        this.homeworkTopic = homeworkTopic;
    }

    public ChapterTitle getChapterTitle() {
        return chapterTitle;
    }

    public void setChapterTitle(ChapterTitle chapterTitle) {
        this.chapterTitle = chapterTitle;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public Date getClassesDate() {
        return classesDate;
    }

    public String getClassesDateInString() {
        return DateUtil.getDateInFormat("dd.MM", classesDate, "BRAK");
    }

    public Long getClassesDateInMs() {
        if (classesDate != null) {
            return classesDate.getTime();
        }
        return null;
    }

    public void setClassesDate(Long classesDateInMs) {
        if (classesDateInMs != null && !classesDateInMs.equals(0L)) {
            classesDate = new Date(classesDateInMs);
        } else {
            classesDate = null;
        }
    }

    public void setClassesDate(Date classesDate) {
        this.classesDate = classesDate;
    }

    public void setHomeworkDate(Long homeworkDateInMs) {
        if (homeworkDateInMs != null && !homeworkDateInMs.equals(0L)) {
            homeworkDate = new Date(homeworkDateInMs);
        } else {
            homeworkDate = null;
        }
    }

    public Date getHomeworkDate() {
        return homeworkDate;
    }

    public String getHomeworkDateInString() {
        return DateUtil.getDateInFormat("dd.MM", homeworkDate, "BRAK");
    }

    public Long getHomeworkDateInMs() {
        if (homeworkDate != null) {
            return homeworkDate.getTime();
        }
        return null;
    }

    public void setHomeworkDate(Date homeworkDate) {
        this.homeworkDate = homeworkDate;
    }

    public TagLesson getTagLesson() {
        return tagLesson;
    }

    public void setTagLesson(TagLesson tagLesson) {
        this.tagLesson = tagLesson;
    }

    @Override
    public String toString() {
        return "LessonProgram{" +
                "id=" + id +
                ", classesTopics=" + classesTopics +
                ", homeworkTopic=" + homeworkTopic +
                ", chapterTitle=" + chapterTitle +
                ", classesDate=" + classesDate +
                ", homeworkDate=" + homeworkDate +
                ", tagLesson=" + tagLesson +
                ", order=" + order +
                '}';
    }

    @Override
    public int compareTo(LessonProgram toCompare) {
        return getOrder().compareTo(toCompare.getOrder());
    }
}